﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;

public partial class Report_MonthSheet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BindData();
    }

    private void BindData()
    {
        string startTime, endTime;
        if (DropDownList1.SelectedValue == "0")
        {
            startTime = DateTime.Now.ToString("yyyy-MM-01");
            endTime =
                DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
        }
        else
        {
            startTime = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01");
            endTime =
                DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
        }

        DataTable dt = new OrderBLL().GetDailySheet(new BranchBLL().GetBranchNameByBranchID(new BranchBLL().GetBranchIDByLoginName(User.Identity.Name)), startTime,
                                                                   endTime, "999", "999", 0);

        GridView1.DataSource = dt;
        GridView1.DataBind();

        var query = dt.AsEnumerable().GroupBy(t => t.Field<string>("币种"))
                      .Select(g => new
                      {
                          币种 = g.Key,
                          成交价格 = g.Sum(m => Convert.ToInt32(m.Field<Decimal>("成交价格")))
                      });

        GridView2.DataSource = query;
        GridView2.DataBind();
    }

    public string GetCss(object str)
    {
        if (string.IsNullOrEmpty(str.ToString()))
        {
            return "";
        }
        return "";
    }
}